package com.lecture.view.bean;

import javax.faces.application.FacesMessage;

import com.lecture.hibernate.pojo.Account;
import com.lecture.hibernate.pojo.Messagebox;
import com.lecture.service.AccountService;
import com.lecture.service.MessageService;
import com.lecture.util.DateUtils;
import com.lecture.view.builder.MessageBuilder;
import com.lecture.view.util.MessageFactory;
import com.lecture.hibernate.pojo.Teacher;

public class SendMessageBean extends BaseBean {
	private String msTitle;

	private String msContent;

	private String msRemark;

	private Account logonAccount;

	private AccountService accountService;

	private MessageService messageService;

	public SendMessageBean() {
		super();
	}

	public String getMsContent() {
		return msContent;
	}

	public void setMsContent(String msContent) {
		this.msContent = msContent;
	}

	public String getMsRemark() {
		return msRemark;
	}

	public void setMsRemark(String msRemark) {
		this.msRemark = msRemark;
	}

	public String getMsTitle() {
		return msTitle;
	}

	public void setMsTitle(String msTitle) {
		this.msTitle = msTitle;
	}

	public Account getLogonAccount() {
		return this.logonAccount;
	}

	public void setLogonAccount(Account account) {
		this.logonAccount = account;
	}

	public AccountService getAccountService() {
		return accountService;
	}

	public void setAccountService(AccountService accountService) {
		this.accountService = accountService;
	}

	public MessageService getMessageService() {
		return messageService;
	}

	public void setMessageService(MessageService messageService) {
		this.messageService = messageService;
	}

	public String sendmessage() {
		try {
			Messagebox message = MessageBuilder.createMessagebox(this);
			if(logonAccount==null)
				System.out.println("loginAccount is null");
			Teacher teacher =logonAccount.getTeacher();
			java.sql.Date msDate = DateUtils.getSystemSDate();
			message.setMsDate(msDate);
			message.setTeacher(teacher);
			message.setStudent(logonAccount.getStudent());
			messageService.saveMessageBox(message);
			FacesMessage fmessage = MessageFactory.getMessage(this.context,
					"page.comm_fsxx.success");
			context.addMessage(null, fmessage);
			return NavigationResults.SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			FacesMessage message = MessageFactory.getMessage(this.context,
			"page.comm_fsxx.error");
			context.addMessage(null, message);
			return NavigationResults.FAILURE;
		}
	
	}

}
